/*Sean Waitkus 364 Program 2 MSmallest class
 * This class takes in an array of size n and creates a queue of size m based on the length of the passed in array "small". 
 * It loops through the passed in "array" of size n indexed by the array "small" and adds the values from array of size n to the queue
 * once complete it removes the elements from the queue and stores them from smallest to largest in the array "small"
 * formatted using eclipse
 */

import java.util.PriorityQueue;

public class MSmallest {

	public static void mSmallest(Integer[] array, Integer[] small) {
		// initializes the queue based on an array of size M
		PriorityQueue<Integer> queue = new PriorityQueue<Integer>(small.length);
		// adds m elements based on the length of an array of size M
		for (int m = 0; m < small.length; m++) {
			// adds the element to the queue
			queue.add(array[m]);
		}
		// adds the next element from an array of size N indexed by an array of
		// size M
		for (int n = small.length; n < array.length; n++) {

			queue.add(array[n]);

		}
		// removes the elements from the queue and inserts them into an array of
		// M length
		for (int m = 0; m < small.length; m++) {
			small[m] = queue.remove();

		}

	}

}
